// UVa 1160 X-Posives
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int par[N];
int find(int x) { return par[x] = par[x] == x ? x : find(par[x]); }
int main() {
  while (true) {
    for (int i = 1; i <= (int)1e5; ++i) par[i] = i;
    vector<pair<int, int>> ex;
    while (true) {
      int n, m;
      if (cin >> n) {
        if (n != -1)
          cin >> m;
        else
          break;
        ex.push_back({n, m});
      } else
        return 0;
    }
    int cnt = 0;
    for (auto &it : ex) {
      auto u = it.first, v = it.second;
      u = find(u);
      v = find(v);
      if (u == v)
        cnt++;
      else
        par[u] = v;
    }
    cout << cnt << endl;
  }
}
